﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Eventhere.Work;
using System.IO.IsolatedStorage;

namespace Eventhere.NewEvent
{
    public partial class NewEvent : PhoneApplicationPage
    {
        public NewEvent()
        {
            InitializeComponent();

            List<String> l = new List<string>();
            foreach (var v in Enum.GetValues(typeof(Calendar.TypeCycles)))
            {
                l.Add(v.ToString());
            }
            
            ListTypeCycle.ItemsSource = l;

        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            Event CurrentEvent = new Event();
            IsolatedStorageSettings.ApplicationSettings["CurrentEvent"] = null ;
            IsolatedStorageSettings.ApplicationSettings["CurrentEvent"] = CurrentEvent;

            NavigationService.Navigate(new Uri("/AddContact.xaml?TypeAjout="+AddContact.TypesAdd.Event.ToString()+"", UriKind.Relative));

        }
        
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            DateTime startdate = DateTime.Parse(this.StartDatePicker.Value.ToString());
            DateTime starttime = DateTime.Parse(this.StartTimePicker.Value.ToString());
            DateTime startdateEvent = new DateTime(startdate.Year, startdate.Month, startdate.Day, starttime.Hour, starttime.Minute, starttime.Second);
            DateTime enddate = DateTime.Parse(this.EndDatePicker.Value.ToString());
            DateTime endtime = DateTime.Parse(this.EndTimePicker.Value.ToString());
            DateTime enddateEvent = new DateTime(enddate.Year, enddate.Month, enddate.Day, endtime.Hour, endtime.Minute, endtime.Second);

            Calendar CurrentCalendar = new Calendar();
            CurrentCalendar.DateStartCalendar = startdateEvent;
            CurrentCalendar.DateEndCalendar = enddateEvent;

            //COUCOUCOUOCUOU
            Event lal = new Event();
            Event CurrentEvent;
            if (IsolatedStorageSettings.ApplicationSettings.Contains("CurrentEvent"))
            {
                CurrentEvent = ((Event)IsolatedStorageSettings.ApplicationSettings["CurrentEvent"]);
                CurrentEvent.CalendarEvent = CurrentCalendar;
                CurrentEvent.ContentEvent = this.ContentTextbox.Text ;
                CurrentEvent.NameEvent = this.EventNameTextbox.Text;
            }
            else
                CurrentEvent = new Event(CurrentCalendar, this.EventNameTextbox.Text, this.ContentTextbox.Text);

            List<Event> events = (List<Event>)IsolatedStorageSettings.ApplicationSettings["Events"];
            events.Add(CurrentEvent);
            IsolatedStorageSettings.ApplicationSettings["Events"] = events;
        }

    }
}